package com.baizhi.cmfz.test;

import com.baizhi.cmfz.CmfzApplication;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = CmfzApplication.class)
public class TwoShiro {

    private String username="lisi";
    private String password="123456";
    @Test
    public  void two(){
        IniSecurityManagerFactory managerFactory=new IniSecurityManagerFactory("E:\\iedaWork\\cmfz\\src\\main\\resources\\shiro.ini");
        SecurityManager securityManager=managerFactory.getInstance();
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject=SecurityUtils.getSubject();
        UsernamePasswordToken token=new UsernamePasswordToken(username,password);
        try{
            subject.login(token);
            System.out.println("登录成功");
        }catch (UnknownAccountException e){
            System.out.println("账号错误");
        }catch (IncorrectCredentialsException e){
            System.out.println("密码错误");
        }
        Boolean a=subject.isAuthenticated();
        System.out.println(a);

    }



}
